package cc.git.liuyan.customeraiagent.core.bigmodel.abstrct;

import cc.git.liuyan.customeraiagent.core.bigmodel.BigModel;
import cc.git.liuyan.customeraiagent.core.bigmodel.BigModelApiClient;
import cc.git.liuyan.customeraiagent.core.bigmodel.BigModelProvider;
import cc.git.liuyan.customeraiagent.core.bigmodel.BigModelProviderInfo;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public abstract class AbstractBigModelProvider implements BigModelProvider {
    private final BigModelProviderInfo providerInfo;
    protected final BigModelApiClient apiClient;
    private final Map<String, BigModel> bigModelMap = new ConcurrentHashMap<>();

    public AbstractBigModelProvider(BigModelProviderInfo providerInfo, Supplier<BigModelApiClient> embeddingApiClientSupplier) {
        this.providerInfo = providerInfo;
        this.apiClient = embeddingApiClientSupplier.get();
    }

    @Override
    public final BigModelProviderInfo getProviderInfo() {
        return this.providerInfo;
    }

    @Override
    public final BigModel getBigModel(String modelName) {
        if (this.bigModelMap.containsKey(modelName)) {
            return this.bigModelMap.get(modelName);
        } else {
            BigModel BigModel = this.createBigModel(modelName);
            this.bigModelMap.put(modelName, BigModel);
            return BigModel;
        }
    }

    protected abstract BigModel createBigModel(String modelName);

}
